<template>
	<div>
    <promoter :show-complete-icon="showCompleteIcon" :base-url="baseUrl" :headers="headers" :disabled="disabled" v-if="nodeConfig.type==0" v-model="nodeConfig"></promoter>

    <approver :show-complete-icon="showCompleteIcon" :base-url="baseUrl" :headers="headers" :disabled="disabled" v-if="nodeConfig.type==1" v-model="nodeConfig"></approver>

    <send :show-complete-icon="showCompleteIcon" :base-url="baseUrl" :headers="headers" :disabled="disabled" v-if="nodeConfig.type==2" v-model="nodeConfig"></send>
    
    <end v-if="nodeConfig.type==6" :disabled="disabled" v-model="nodeConfig"></end>
    
    <branch :show-complete-icon="showCompleteIcon" :base-url="baseUrl" :headers="headers" :disabled="disabled" v-if="nodeConfig.type==4" v-model="nodeConfig">
    	<template v-slot="slot">
    		<node-wrap :show-complete-icon="showCompleteIcon" :base-url="baseUrl" :headers="headers" :disabled="disabled" v-if="slot.node" v-model="slot.node.childNode"></node-wrap>
    	</template>
    </branch>

    <node-wrap :show-complete-icon="showCompleteIcon" :base-url="baseUrl" :headers="headers" :disabled="disabled" v-if="nodeConfig.childNode" v-model="nodeConfig.childNode"></node-wrap>
  </div>

</template>

<script>
	import approver from './nodes/approver.vue'
	import promoter from './nodes/promoter.vue'
	import branch from './nodes/branch.vue'
	import send from './nodes/send.vue'
  import end from './nodes/end.vue'
	export default {
    name: 'node-wrap',
		props: {
			value: { type: Object, default: () => {} },
      disabled: {
        type: Boolean,
        default: false
      },
      baseUrl: {
        type: String,
        default: ''
      },
      headers: {
        type: Object,
        default: () => {
          return {}
        }
      },
      showCompleteIcon: {
        type: Boolean,
        default: false
      }
		},
		components: {
			approver,
			promoter,
			branch,
			send,
      end
		},
		data() {
			return {
				nodeConfig: {},
			}
		},
		watch:{
			value(val){
				this.nodeConfig = val
			},
			nodeConfig(val){
				this.$emit("input", val)
			}
		},
		mounted() {
			this.nodeConfig = this.value
		},
		methods: {

		}
	}
</script>

<style>
</style>
